<?php

class Mnt_IndexController extends Base_Controller_Action
{
    public function init()
    {
        #print_r($GLOBALS['_COOKIE']);exit;
        if (!Base_Auth::isLogin()) {
            $this->_helper->LoginJump();
        }
    }

	public function indexAction()
	{
		$this->view->user = Base_Auth::getIdentity();
		
		//module menu
        $iconMenus = $linkMenus = array();
        $dir = new DirectoryIterator(MODULES_PATH);

        foreach ($dir as $file) {
            if ($file->isDot() || !$file->isDir()) {
                continue;
            }

            $module    = $file->getFilename();
            if (preg_match('/^[^a-z]/i', $module)) {
                continue;
            }
            $menuFilePath = $file->getPathname(). DIRECTORY_SEPARATOR .'menu.ini';

            if (is_file($menuFilePath)) {
                $menus = new Zend_Config_Ini($menuFilePath);
                
                //link menus
                if (isset($menus->link)) {
                    foreach ($menus->link->toArray() as $name=> $menu) {
                        $menu['url']['module'] = $module;
                        $linkMenus[$module .$name] = $menu;
                    }
                }
                //icon menus
                if (isset($menus->icon)) {
                    foreach ($menus->icon->toArray() as $name=> $menu) {
                        $menu['url']['module'] = $module;
                        $iconMenus[$module .$name] = $menu;
                    }
                }
                //main menus
                if (isset($menus->main)) {
                    foreach ($menus->main->toArray() as $name=> $menu) {
                        $menu['url']['module'] = $module;
                        $mainMenus[$module .$name] = $menu;
                    }
                }
            }
        }
        
		$this->view->linkMenus = $linkMenus;
		$this->view->iconMenus = $iconMenus;
		$this->view->mainMenus = $mainMenus;
		
		$this->view->module = $this->getFrontController()->getDefaultModule();
        $this->_helper->layout->setLayout('browse');
	}
}